refactor: migrate lib.autoExternal to output.autoExternal#1641
refactor: migrate lib.autoExternal to output.autoExternal#1641elecmonkey wants to merge 4 commits into
lib.autoExternal to output.autoExternal#1641Conversation
Deploying rslib with
|
| Latest commit: |
7123285
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://06e6534d.rslib.pages.dev |
| Branch Preview URL: | https://refactor-migrate-auto-extern.rslib.pages.dev |
Leverage Rsbuild 2.0.7's native output.autoExternal instead of maintaining custom externalization logic. The deprecated lib.autoExternal is kept as a thin shim with a logger warning. - Remove composeAutoExternalConfig, composeExternalsWarnConfig, composeModuleImportWarn, handleMatchedExternal, getAutoExternalDefaultValue - Set autoExternal default in composeFormatConfig (ESM/CJS bundle → true) - Add exeExternalOverride to disable autoExternal for exe mode - CLI writes to output.autoExternal instead of lib.autoExternal - Add autoExternal field to RslibOutputConfig type
- Add output.autoExternal section to Rsbuild output docs (en/zh) - Add deprecation warning banner to lib.autoExternal docs (en/zh) - Update output.externals description to reference output.autoExternal
b2e6446 to
1a5b36f
Compare
There was a problem hiding this comment.
Pull request overview
This PR migrates Rslib’s dependency auto-externalization behavior from the legacy lib.autoExternal option to Rsbuild’s output.autoExternal, aligning implementation with Rsbuild’s built-in capability while keeping backward compatibility via a deprecation shim.
Changes:
- Add
output.autoExternaldocumentation (EN/ZH) and marklib.autoExternalas deprecated in docs and public config typings. - Refactor core config composition to rely on
output.autoExternal(and remove the previous customcomposeAutoExternalConfigimplementation and its unit tests). - Update CLI option wiring and test expectations/snapshots to reflect the new configuration location.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| website/docs/zh/config/rsbuild/output.mdx | Add output.autoExternal docs and update output.externals wording to reference it. |
| website/docs/zh/config/lib/auto-external.mdx | Add deprecation warning pointing to output.autoExternal. |
| website/docs/en/config/rsbuild/output.mdx | Add output.autoExternal docs and update output.externals wording to reference it. |
| website/docs/en/config/lib/auto-external.mdx | Add deprecation warning pointing to output.autoExternal. |
| tests/integration/externals/index.test.ts | Remove the module-import warning integration test that depended on the old warning logic. |
| tests/integration/auto-external/index.test.ts | Remove the module-import warning integration test and simplify imports accordingly. |
| packages/core/tests/external.test.ts | Remove unit tests for the deleted composeAutoExternalConfig. |
| packages/core/tests/config.test.ts | Update CLI snapshot expectations for new output.autoExternal location. |
| packages/core/tests/cli.test.ts | Assert CLI populates lib.output.autoExternal instead of lib.autoExternal. |
| packages/core/tests/snapshots/config.test.ts.snap | Update snapshots to reflect externals ordering and output.autoExternal presence. |
| packages/core/src/types/config.ts | Deprecate lib.autoExternal in typings and add output.autoExternal override typing/docs. |
| packages/core/src/config.ts | Remove custom auto-externalization + warning logic; set defaults via output.autoExternal; add deprecation shim. |
| packages/core/src/cli/init.ts | Wire --auto-external CLI flag to lib.output.autoExternal. |
Comments suppressed due to low confidence (2)
website/docs/en/config/lib/auto-external.mdx:15
- The page frontmatter/intro still describes
lib.autoExternalas an active configuration, but the option is now deprecated. Update the page description/intro to clearly state it’s kept for backward compatibility and point readers tooutput.autoExternalas the canonical option.
# lib.autoExternal
:::warning
`lib.autoExternal` is deprecated. Please use [output.autoExternal](/config/rsbuild/output#outputautoexternal) instead.
:::
:::info
`autoExternal` is a specific configuration for bundle mode. It will not take effect in bundleless mode (set [lib.bundle](/config/lib/bundle) to `false`) since deps will not be bundled in bundleless mode.
website/docs/zh/config/lib/auto-external.mdx:15
- 当前页面的描述仍然把
lib.autoExternal当作主要配置项,但这里已标记为废弃。建议同步更新页面的描述/开头说明,明确这是兼容性保留配置,并引导用户迁移到output.autoExternal。
# lib.autoExternal
:::warning
`lib.autoExternal` 已废弃,请使用 [output.autoExternal](/config/rsbuild/output#outputautoexternal) 代替。
:::
:::info
`autoExternal` 是 bundle 模式的特定配置。在 bundleless 模式(将 [lib.bundle](/config/lib/bundle) 设置为 `false`)下不会生效,因为 bundleless 模式下依赖不会被打包。
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
lib.autoExternal to output.autoExternal to leverage Rsbuild's capabilitylib.autoExternal to output.autoExternal
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 71232855db
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| return { | ||
| output: { | ||
| filenameHash: false, | ||
| ...(bundle && { autoExternal: true }), |
There was a problem hiding this comment.
Preserve object externals precedence for autoExternal
Switching to output.autoExternal here removes the old userExternals filtering logic, so in the default Node target path (composeTargetConfig adds built-in externals at output.externals) the merged externals become an array instead of a plain object. Rsbuild only de-duplicates autoExternal package keys when output.externals is an object, so configs like output.externals: { react: 'react1' } can still auto-externalize react subpaths (for example react/jsx-runtime) unexpectedly, changing bundling behavior compared to previous Rslib behavior and potentially breaking runtime/module resolution assumptions.
Useful? React with 👍 / 👎.
Migrated
lib.autoExternalto reuse Rsbuild's nativeoutput.autoExternal(available since Rsbuild 2.0.7).The deprecated
lib.autoExternalfield is preserved that maps tooutput.autoExternalwith a deprecation warning.